package com.project.rfidtodb.service.Impl;

import com.project.rfidtodb.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.Executor;

/**
 * 定时任务服务实现类
 */
@Service
@Slf4j
public class TimerServiceImpl implements TimerService {

    @Resource
    private Executor taskExecutor;
    @Resource
    private List<ProcessService> processServices;



    /**
     * 数据库处理过程
     * @throws Exception
     */
//    @Scheduled(cron = "0 0 0 * * ? ")
//    @Scheduled(cron = "0 0/5 * * * ?")
    @Override
    public void dbProcess() throws Exception {
        log.info("dbProcess invoke......");
        long startTime = System.currentTimeMillis();

        for (ProcessService service : processServices) {

                try {
                    service.process();
                } catch (Exception e) {
                    log.info("dbProcess error: {}", e.getMessage());
                }

        }

        log.info("dbProcess end, cost time: {}ms", System.currentTimeMillis() - startTime);


    }
}
